<template>
  <div class="content">
    <p>物业明细表</p>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
    >
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    getTenementDetail
  } from '@/api/teambalance1'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'

  const tenementMonth = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width" :fixed="colConfig.fixed">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const configs = {
    props: ['colConfig'],
    template: `
  <el-table-column :label="colConfig.label">
            <el-table-column  v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                <span slot-scope="scope" >
                    <span>{{scope.row[item.prop]}}</span>
                </span>
            </el-table-column>
  </el-table-column>
  `
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    props: ['viewDetailList'],
    data() {
      return {
        colConfigs: [
          { prop: 'floorName', label: '楼层（F）', width: '100', fixed: true },
          { prop: 'teamName', label: '部门/所', width: '150', fixed: true },
          { prop: 'tenementMonth', label: '结算月份', width: '100', fixed: true, component: tenementMonth },
          { prop: 'teamCount', label: '部门人数', width: '100' },
          { prop: 'peopleCount', label: '总人数', width: '100' },
          { prop: 'companyArea', label: '总面积(㎡)', width: '100' },
          { prop: 'departmentArea', label: '部门面积(㎡)', width: '100' },
          {
            label: '房租', children: [
              { prop: 'rentPrice', label: '总费用(元)', width: '120' },
              { prop: 'rentTeamPrice', label: '部门费用(元)', width: '120' }
            ], component: configs
          },
          {
            label: '物业费', children: [
              { prop: 'tenementPrice', label: '单价(元)', width: '100' },
              { prop: 'tenementMonthPrice', label: '本月费用(元)', width: '100' }
            ], component: configs
          },
          {
            label: '能耗', children: [
              { prop: 'energyPrice', label: '单价(元)', width: '100' },
              { prop: 'energyMonthPrice', label: '本月费用(元)', width: '100' }
            ], component: configs
          },
          {
            label: '空调', children: [
              { prop: 'vrvPrice', label: '单价(元)', width: '100' },
              { prop: 'vrvMonthPrice', label: '本月费用(元)', width: '100' }
            ], component: configs
          },
          {
            label: '水', children: [
              { prop: 'waterPrice', label: '单价(元)', width: '100' },
              { prop: 'waterMonthPrice', label: '本月费用(元)', width: '100' }
            ], component: configs
          },
          {
            label: '照明电费', children: [
              { prop: 'illuminationPrice', label: '单价(元)', width: '100' },
              { prop: 'illuminationMonthPrice', label: '本月费用(元)', width: '100' }
            ], component: configs
          },
          { prop: 'pooled', label: '公摊(元)', width: '100' },
          {
            label: '11楼房租核算', children: [
              { prop: 'roomPrice', label: '单间单价(元)', width: '100' },
              { prop: 'roomCount', label: '数量', width: '100' },
              { prop: 'roomSubtotal', label: '小计(元)', width: '100' },
              { prop: 'stationPrice', label: '工位单价(元)', width: '100' },
              { prop: 'stationCount', label: '数量', width: '100' },
              { prop: 'stationSubtotal', label: '小计(元)', width: '100' },
              { prop: 'rentTotal', label: '合计(元)', width: '100' }
            ], component: configs
          },
          {
            label: '按面积核算', children: [
              { prop: 'illuminationBeforeMonth', label: '照明上月读数', width: '120' },
              { prop: 'illuminationMonth', label: '照明本月度数', width: '120' },
              { prop: 'illuminationFee', label: '照明费用(元)', width: '100' },
              { prop: 'vrvFee', label: '空调(元)', width: '100' },
              { prop: 'waterFee', label: '水(元)', width: '100' },
              { prop: 'energyFee', label: '能耗(元)', width: '100' },
              { prop: 'tenementFee', label: '物业(元)', width: '100' },
              { prop: 'areaSubtotal', label: '小计(元)', width: '100' }
            ], component: configs
          },
          { prop: 'total', label: '总计(元)', width: '100' },
          { slot: 'opt' }
        ],
        noConfigs: [
          { prop: 'floorName', label: '楼层（F）', width: '100', fixed: true },
          { prop: 'teamName', label: '部门/所', width: '150', fixed: true },
          {
            label: '房租', children: [
              { prop: 'rentTeamPrice', label: '部门费用(元)', width: '120' }
            ], component: configs
          },
          {
            label: '11楼房租核算', children: [
              { prop: 'roomPrice', label: '单间单价(元)', width: '100' },
              { prop: 'roomCount', label: '数量', width: '100' },
              { prop: 'stationPrice', label: '工位单价(元)', width: '100' },
              { prop: 'stationCount', label: '数量', width: '100' },
              { prop: 'rentTotal', label: '合计(元)', width: '100' }
            ], component: configs
          },
          {
            label: '按面积核算', children: [
              { prop: 'illuminationFee', label: '照明费用(元)', width: '100' },
              { prop: 'vrvFee', label: '空调(元)', width: '100' },
              { prop: 'waterFee', label: '水(元)', width: '100' },
              { prop: 'energyFee', label: '能耗(元)', width: '100' },
              { prop: 'tenementFee', label: '物业(元)', width: '100' }
            ], component: configs
          },
          { prop: 'total', label: '总计(元)', width: '100' }
        ],
        listLoading: true,
        dialogType: 0,
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        pca: pca,
        rules: {},
        visible: false
      }
    },
    created() {
    },
    computed: {
      global() {
        return global
      },
      teamId() {
        return this.$store.state.user.teamId
      },
      roleType() {
        return this.$store.state.user.roleType
      }
    },
    methods: {
      fetchData() {
        this.viewDetailList.pageNum = this.pageNum
        this.viewDetailList.pageSize = this.pageSize
        this.listLoading = true
        getTenementDetail(this.viewDetailList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      }
    },
    watch: {
      'viewDetailList': {
        handler(newValue, oldValue) {
          this.fetchData()
        },
        immediate: true
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .content {
    padding: 20px;
  }

</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
